package com.library.servlet;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.library.dao.BookTitle;
import com.library.dao.BookTitleDAO;
import com.library.dao.DAOFactory;
import com.library.dao.MySQLDAOFactory;

/**
 * Servlet implementation class InitializeHome
 */
@WebServlet("/InitializeHome")
public class InitializeHome extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public InitializeHome() {
        super();
        
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//TODO thuc hien tim random nhung cuon sach thu vien in ra man hinh
		DAOFactory factory = new MySQLDAOFactory();
		BookTitleDAO dao = factory.getBookTitleDAO();
		ArrayList<BookTitle> books = dao.getNRandomBook(10);
		request.setAttribute("books", books);
		String add = "home.jsp";
		 RequestDispatcher dispatcher =
			      request.getRequestDispatcher(add);
			    dispatcher.forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
	}

}
